﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using WpfApp1.Httpwork;

namespace WpfApp1.chaxun
{
    class chaxunM
    {
        public async static void HttpchaxunPost(chaxunInterface httpinter, string url, string content)
        {
            Boolean b = true;
            string result = "";
            HttpWebResponse resp = null;
            await Task.Run(() =>
            {
                HttpWebRequest req = Http.postHttp(url, content);
                try
                {
                    resp = (HttpWebResponse)req.GetResponse();
                    b = true;
                }
                catch (WebException ex)
                {
                    resp = (HttpWebResponse)ex.Response;
                    b = false;
                }
                Stream stream = resp.GetResponseStream();
                //获取响应内容
                using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
                {
                    result = reader.ReadToEnd();
                }
            });
            if (b)
            {
                httpinter.chaxunok(result);
            }
            else
            {
                httpinter.chaxunno(result);
            }
        }
    }
}
